package com.qf.rbac2202.sys.controller;

import com.qf.rbac2202.sys.entity.SysRole;
import com.qf.rbac2202.sys.service.ISysRoleService;
import com.qf.rbac2202.utils.PageVo;
import com.qf.rbac2202.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author dong_
 * @since 2022-10-28
 */
@RestController
@RequestMapping("/sys/role")
public class SysRoleController {

	@Autowired
	ISysRoleService iSysRoleService;

	@GetMapping("/list")
	@RequiresPermissions("sys:role:list")
	public R list( @RequestParam Map< String, Object > params ) {

		PageVo pageVo=iSysRoleService.getPageVo( params );

		return R.ok( ).put( "page",pageVo );
	}

	@PostMapping("/save")
	public R save( @RequestBody SysRole sysRole ) {
		iSysRoleService.saveRole( sysRole );

		return R.ok( );
	}

	@GetMapping("/info/{roleId}")
	public R info( @PathVariable("roleId") Long roleId ) {
		SysRole sysRole=iSysRoleService.getRoleById( roleId );

		return R.ok( ).put( "role",sysRole );
	}

	@PostMapping("/delete")
	public R deleteByRoleId( @RequestBody List<String> roleIds ) {
		iSysRoleService.deleteId(roleIds  );
		return R.ok( );
	}

	@PostMapping("/update")
	public R updateByRoleId( @RequestBody SysRole sysRole ) {
		iSysRoleService.updateRole( sysRole );
		return R.ok( );
	}
}
